package cc.langk.sms.remote;

import cc.langk.sms.base.Result;
import cc.langk.sms.service.SmsHistortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/")
public class SmsController {

    @Autowired
    private SmsHistortService smsHistortService;

    @RequestMapping("/")
    @ResponseBody
    public String home() {
        return "Hello World!";
    }


    @RequestMapping("/sendAliSms/{phone}")
    @ResponseBody
    public Result sendAliSms(@PathVariable String phone) {
        try {
            if (phone == null || phone.length() < 11) {
                return new Result.ResultBuiler().failed("手机号格式不对");
            }
            boolean result = smsHistortService.sendAliSms(phone);
            if (result) {
                return new Result.ResultBuiler().success("发送成功");
            }else {
                return new Result.ResultBuiler().failed("发送失败");
            }
        }catch (Exception e){
            return new Result.ResultBuiler().error();

        }

    }


    @RequestMapping("/sendTencentSms/{phone}")
    @ResponseBody
    public Result sendTencentSms(@PathVariable String phone) {
        try {
            if (phone == null || phone.length() < 11) {
                return new Result.ResultBuiler().failed("手机号格式不对");
            }
            boolean result = smsHistortService.sendTencentSms(phone);
            if (result) {
                return new Result.ResultBuiler().success("发送成功");
            }else {
                return new Result.ResultBuiler().failed("发送失败");
            }
        }catch (Exception e){
            return new Result.ResultBuiler().error();

        }

    }

}
